(function(angular) {
	"use strict";
	angular.module("fs.waf").factory("settleInitLoanService", settleInitLoanService);
	settleInitLoanService.$inject = [ "$filter", "txnService" ];
	function settleInitLoanService($filter, txnService) {

		function getCompanyCodeByAlloc(settlement, allocCode) {
			var custCode = "", encode = $filter("encode");
			if (allocCode == "CUSTOMER")
				custCode = encode(settlement.loan.loanInfo.custCode);
			else if (allocCode == "OBLIGOR")
				custCode = encode(settlement.loan.loanInfo.obligorCode);
			else
				custCode = encode(settlement.loan.loanInfo.custCode);

			return custCode;
		}
		function getCcy(settlement) {
			return settlement.loan.loanInfo.loanCcy;
		}
		function getTxnAmount(settlement) {
			return settlement.loan.loanInfo.loanAmt;
		}
		function getAssetId(settlement) {
			return settlement.loan.loanInfo.assetId;
		}
		function getProdCodeAndType(settlement) {
			var prodCode = settlement.loan.loanInfo.prodCode;
			var prodType = settlement.loan.loanInfo.prodType;
			return {
				prodCode : prodCode,
				prodType : prodType
			};
		}
		function getDeductIntAndFeeFlag(settlement) {
			return {
				deductIntFlag : settlement.loan.loanInfo.deductIntFlag,
				deductFeeFlag : settlement.loan.loanInfo.deductFeeFlag
			};
		}
		function getGeneralConfig(layoutConfig) {
			return angular.copy(layoutConfig.formConfigs.general);
		}
		
		function getGeneralModel(settlement) {
			return settlement.loan;
		}
		
		function getBackMessage() {
			return "title.infobar.loan.update";
		}
		
		function getLayout(settlement, packageSuffix) {
			return txnService.getLayout("settlement", packageSuffix, false, "LOAN", settlement.loan.loanInfo.prodType, settlement.loan.loanInfo.prodSubtype);
		}
		
		function processDynaparmConfig(loyout){
			angular.forEach(loyout.formConfigs.general.gridConfigs, function(gridConfig){
				if(gridConfig.model.indexOf("dynamicParams.") != -1){
					gridConfig.model = "loan." + gridConfig.model;
				}
			});
		}
		
		return {
			getCcy : getCcy,
			getTxnAmount : getTxnAmount,
			getAssetId : getAssetId,
			getCompanyCodeByAlloc : getCompanyCodeByAlloc,
			getProdCodeAndType : getProdCodeAndType,
			getDeductIntAndFeeFlag : getDeductIntAndFeeFlag,
			getGeneralConfig : getGeneralConfig,
			getGeneralModel : getGeneralModel,
			getBackMessage : getBackMessage,
			getLayout : getLayout,
			processDynaparmConfig : processDynaparmConfig
		};
	}
})(angular);
